<!DOCTYPE html>
<html>
<head>
    <!-- 新增这行 ↓↓↓ -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta charset="UTF-8">
    <title>图片标签系统</title>
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            max-width: 90%;
            margin: 0 auto;
            padding: 20px;
        }
        .image-container {
            margin-bottom: 30px;
            border-bottom: 1px dashed #ccc;
            padding-bottom: 20px;
        }
        img {
            max-width: 100%;
            height: auto;
            display: block;
            margin: 0 auto 10px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .tags-container {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            justify-content: center;
            margin-top: 10px;
        }
        .tag {
            background-color: #f0f0f0;
            color: #ff0000;
            padding: 4px 10px;
            border-radius: 15px;
            font-size: 12px;
            white-space: nowrap;
            cursor: pointer;
            transition: background 0.2s;
        }
        #gallery-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
            padding: 20px 0;
        }
        
        .image-container {
            background: white;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .tag-controls {
            display: flex;
            margin-top: 10px;
        }
        .new-tag-input {
            flex-grow: 1;
            padding: 5px 10px;
        }
        .add-tag-btn {
            margin-left: 5px;
            cursor: pointer;
            min-width: 44px;  /* 苹果推荐的最小触控尺寸 */
            padding: 12px;
        }
        /* 添加加载状态提示 */
        .add-tag-btn.loading {
            opacity: 0.6;
            pointer-events: none;
        }
        
        .tag:hover {
            background: #d9d9d9 !important;
        }
        #edit-modal {
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
            border-radius: 5px;
            transition: opacity 0.3s, transform 0.3s;
        }
        #tag-update-btn, #tag-delete-btn, #tag-cancel-btn {
            padding: 5px 10px;
            margin-left: 5px;
            cursor: pointer;
        }
        .modal-enter {
            opacity: 0;
            transform: translate(-50%, -60%);
        }
        
        .search-bar {
            margin: 20px 0;
            display: flex;
            gap: 10px;
        }
        #search-input {
            flex: 1;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        #search-btn, #reset-btn {
            padding: 8px 16px;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        #reset-btn {
            background: #f44336;
        }
        
        /* 全屏动画效果 */
        #fullscreen-overlay {
            touch-action: none; /* 禁止手势缩放干扰 */
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        #fullscreen-overlay.active {
            opacity: 1;
        }
        #fullscreen-image {
            transition: transform 0.3s ease;
        }
        
        /* 图片容器悬停效果 */
        .image-container img {
            cursor: zoom-in;
            transition: transform 0.2s;
        }
        .image-container img:hover {
            transform: scale(1.02);
        }
        
        /*翻页按钮*/
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
            margin: 30px 0;
            flex-wrap: wrap;
        }
        .pagination button {
            min-width: 44px;
            padding: 8px 12px;
            background: #f0f0f0;
            border: 1px solid #ddd;
            border-radius: 4px;
            cursor: pointer;
        }
        .pagination button:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }
        .page-numbers {
            display: flex;
            gap: 5px;
        }
        .page-numbers button {
            min-width: 30px;
        }
        .page-numbers button.active {
            background: #4CAF50;
            color: white;
            border-color: #4CAF50;
        }
    </style>
</head>
<body>
    <h1>我的图片库</h1><!-- 标题 -->
    
    <div class="search-bar"><!-- 搜索框 -->
        <input type="text" id="search-input" placeholder="输入标签关键词...">
        <button id="search-btn">搜索</button>
        <button id="reset-btn">重置</button>
    </div>
    
    <div id="gallery-container"></div> <!-- 图片将动态插入到这里 -->
    
    <!-- 标签修改弹出框 -->
    <div id="edit-modal" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); background:white; padding:20px; z-index:1000; border:1px solid #ccc;">
        <input type="text" id="tag-edit-input" style="padding:5px; width:200px;">
        <button id="tag-update-btn">更新</button>
        <button id="tag-delete-btn" style="background:#ff6b6b;">删除</button>
        <button id="tag-cancel-btn">取消</button>
    </div>
    <div id="modal-overlay" style="display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:999;"></div>
    
     <!-- 全屏预览 -->
    <div id="fullscreen-overlay" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 1000; cursor: pointer;">
        <img id="fullscreen-image" style="max-width: 90%; max-height: 90%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); object-fit: contain; pointer-events: none;">
    </div>
    
    <!-- 下方翻页按钮 -->
    <div class="pagination">
        <button id="page-prev" disabled>←</button>
        <div class="page-numbers" id="page-numbers"></div>
        <button id="page-next">→</button>
    </div>
    <script>
        // 全局标签数据
        let allTags = {};
    
        // 加载标签数据
        async function loadTags() {
            const response = await fetch('data/tags.json');
            return await response.json();
        }
    
        // 渲染单个图片项（含标签）
        function renderImageItem(imgName, container) {
            const imgDiv = document.createElement('div');
            imgDiv.className = 'image-container';
            imgDiv.innerHTML = `
                <img src="image/${imgName}" alt="${imgName}">
                <div class="tags-container" id="tags-${imgName.replace('.', '-')}"></div>
                <div class="tag-controls">
                    <input type="text" class="new-tag-input" placeholder="输入新标签">
                    <button class="add-tag-btn" data-img="${imgName}">➕ 添加</button>
                </div>
            `;
            container.appendChild(imgDiv);
    
            // 渲染该图片的标签
            if (allTags[imgName]) {
                const tagsContainer = imgDiv.querySelector('.tags-container');
                allTags[imgName].tags.forEach(tag => {
                    const tagElement = document.createElement('span');
                    tagElement.className = 'tag';
                    tagElement.textContent = tag;
                    tagsContainer.appendChild(tagElement);
                });
            }
        }
    
        // // 主加载函数
        // async function renderGallery() {
        //     const [images, tags] = await Promise.all([
        //         fetch('get_images.php').then(r => r.json()),
        //         loadTags()
        //     ]);
            
        //     allTags = tags;
        //     const container = document.getElementById('gallery-container');
        //     container.innerHTML = '';
            
        //     images.forEach(imgName => {
        //         renderImageItem(imgName, container);
        //     });
            
        //     // 新增：渲染完成后绑定事件
        //     if (typeof bindAddTagEvents === 'function') {
        //         bindAddTagEvents();
        //     } else {
        //         console.error('bindAddTagEvents未定义!');
        //     }
        // }
        
        // 修改window.onload
       // window.onload = () => renderGallery(1);
    </script>
    <script src="static/js/tag-manager.js"></script>
</body>
</html>